/*
 * @Author: xiawei 1243162387@qq.com
 * @Date: 2024-03-29 15:25:23
 * @LastEditors: xiawei 1243162387@qq.com
 * @LastEditTime: 2024-04-10 08:59:55
 */
import { defineStore } from 'pinia'
import { getUserInfo } from '@/api'
import { ElMessage } from 'element-plus'
import { UserInfoType } from '@/types/index'
const userStore = defineStore('userStore',{
    state: () => ({ 
        userInfo: {} as UserInfoType
    }),
    actions: {
        async addUser(id: string){
            const { result: userInfo } = await getUserInfo(id);
            if(userInfo){
                this.userInfo = userInfo as UserInfoType;
            }else{
                ElMessage({
                    message: '获取用户信息错误.',
                    type: 'error',
                  })
            }
            return  userInfo;
        },
        clearUser(){
            this.userInfo = {} as UserInfoType;
        }
    }

})
export default userStore